/*
 * @Author: PangLei 
 * @Date: 2017-09-21 13:25:04 
 * @Last Modified by: PangLei
 * @Last Modified time: 2017-09-26 09:55:55
 */



window.onload = function () {
  showModal();
  closeModal();
  errorShow();
  errorHide();
}

// 顶部下拉隐藏菜单
function showDropdown(li) {
  var map_dropdown = li.getElementsByClassName("dropdown_content")[0];
  if (!map_dropdown) return false;
  map_dropdown.style.display = "block";
}
function hideDropdown(li) {
  var map_dropdown = li.getElementsByClassName("dropdown_content")[0];
  if (!map_dropdown) return false;
  map_dropdown.style.display = "none";
}

// 模态窗口
var body = document.getElementsByTagName('body')[0];
var modal = document.getElementsByClassName('modal')[0];

// 显示遮罩层函数
function showBackdrop() {
  var modal_backdrop = document.createElement('div');
  modal_backdrop.setAttribute('class', 'modal_backdrop in');
  body.appendChild(modal_backdrop);
}
// 显示模态对话框
function showModal() {
  var showModalBtn = document.getElementsByClassName('lr_login')[0];
  if (!showModalBtn) return false;
  showModalBtn.onclick = function () {
    modal.setAttribute('class', 'modal show fade_in');
    showBackdrop();
  }
}
// 关闭模态
function closeModal() {
  var modal_close = document.getElementsByClassName('modal_close')[0];
  if (!modal_close) return false;
  modal_close.onclick = function () {
    var modal_backdrop = document.getElementsByClassName('modal_backdrop')[0];
    modal.setAttribute('class', 'modal hide');
    body.removeChild(modal_backdrop);
  }
}


// 简单展示注册页面验证
var form_group = document.getElementsByClassName('form-group');
var help_block = document.getElementsByClassName('help-block');
function addError() {
  for (var i = 0; i < form_group.length; i++) {
    form_group[i].setAttribute('class', 'form-group has-error');
  }
  for (var i = 0; i < help_block.length; i++) {
    help_block[i].setAttribute('class', 'help-block');
  }
}
function removeError() {
  for (var i = 0; i < form_group.length; i++) {
    form_group[i].setAttribute('class', 'form-group');
  }
  for (var i = 0; i < help_block.length; i++) {
    help_block[i].setAttribute('class', 'help-block hide');
  }
}
var btn_register = document.getElementsByClassName('btn-register')[0];
function errorShow() {
  btn_register.onclick = function () {
    addError();
  }
}

var regInput = document.getElementsByTagName('input');
function errorHide() {
  for (var i = 0; i < regInput.length; i++) {
    var element = regInput[i];
    element.addEventListener('click', removeError);
  }
}